import { reqGoodsDetailInfoData } from "@/api";
const state = {
    goodDetailInfo:{}
}
const actions = {
    async getGoodsDetailInfoData({commit},id){
        const result = await reqGoodsDetailInfoData(id)
        if(result.code === 200){
        
            commit('SAVE_GOOD_DETAIL_INFO_DATA',result.data)
        }else{
            console.log(result.message);
        }
    }
}
const mutations = {
    //存储数据
    SAVE_GOOD_DETAIL_INFO_DATA(state,payload){
        state.goodDetailInfo = payload //是个对象形式
    },
    //更改skuInfo中大图的位置
    UPDATE_SKUINFO_IMGURL(state,imgUrl){
        state.goodDetailInfo.skuInfo.skuDefaultImg = imgUrl
    }
}
const getters = {
    categoryView(state){
        //进入页面发送请求 还没获取到数据 数据先给到vuex最后才渲染到页面 所以先给个空
        return state.goodDetailInfo.categoryView || {};
    },
    skuInfo(state){
        return state.goodDetailInfo.skuInfo || {}
    },
    spuSaleAttrList(state){
        return state.goodDetailInfo.spuSaleAttrList || []
    }
}
export default {
    namespaced:true,
    state,
    actions,
    mutations,
    getters
}